package com.nkdx.ws.controller;

import com.alibaba.fastjson.JSONObject;
import com.nkdx.ws.annotation.Log;
import com.nkdx.ws.response.ApiResponse;
import com.nkdx.ws.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 *   登录 控制器
 * @author ZZW
 * @date 2022/3/2 2:09 下午
 * @param
 * @return
 */
@Controller
public class LoginController {

    private LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService){
        this.loginService = loginService;
    }

    /**
     *  去登录，登录成功则 去 主页
     * @author ZZW
     * @date 2022/3/2 4:51 下午
     * @param
     * @return
     */
    @Log(module = "用户登录",description = "用户登录")
    @RequestMapping("/login")
    public String login(){

        //判断 如果未登录则进入登录页面，登录成功则进入home 页面
        boolean loginSuccess = loginService.login();
        if (loginSuccess){
            return "home";
        }
        return "login";
    }

    /**
     *    登录校验
     *
     * @author ZZW
     * @date 2022/3/2 4:51 下午
     * @param
     * @return
     */
    @Log(module = "用户登录校验",description = "用户登录校验")
    @RequestMapping("/loginVerification")
    @ResponseBody
    public ApiResponse loginVerification(){
        ApiResponse<Object> resp = new ApiResponse<>();
        return resp.success(loginService.loginVerification());
    }

    /**
     * 登出
     * @author ZZW
     * @date 2022/3/3 10:17 上午
     * @param
     * @return
     */
    @Log(module = "用户退出",description = "用户退出")
    @RequestMapping("/logout")
    public String logout(){
        loginService.logout();
        return "login";
    }
}
